package com.lizemin.controller;

import com.lizemin.clients.OrderClient;
import com.lizemin.clients.StockClient;
import com.lizemin.req.CreateOrderReq;
import com.lizemin.resp.OrderResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lzm
 * @date 2025/4/17 22:10
 * @description
 */
@Slf4j
@RestController
@RefreshScope
public class OrderController implements OrderClient {

    @Value("${app.user.name}")
    private String username;

    @Value("${app.user.age}")
    private String age;

    @Autowired
    private StockClient stockClient;

    @Override
    public String createOrder(@RequestBody CreateOrderReq createOrderReq) {
        log.info("接收到创建订单的请求");
        stockClient.deductStock(createOrderReq.getProductId(), createOrderReq.getCount());
        return "创建成功";
    }

    @Override
    public OrderResp listOrders() {
        throw new RuntimeException("未查到订单信息");
    }

    @Override
    public void getConfig() {
        log.info("用户名：{}，年龄：{}", username, age);
    }

}
